import {CardsType, King, poker} from "./types";
import {CardValue, Color} from "./enums";

export function createCardGroup(): CardsType {
    let CardGroup: CardsType = []
    //获取牌的花色和每种花色的数量
    let ColorValues = Object.values(Color)
    let CardValues = Object.values(CardValue)
    CardValues.forEach(p => {
        ColorValues.forEach(c => {
            CardGroup.push({
                Color: c,
                CardValue: p,
                valueOf(): string {
                    return this.Color + this.CardValue
                }
            } as poker)
        })
    })
    CardGroup.push({
        types:'small',
        valueOf(): string {
            return '大王'
        }
    }as King)
    CardGroup.push({
        types:'Big',
        valueOf(): string {
            return '小王'
        }
    }as King)
    return CardGroup
}

export function printCardGroup(CardGroup: CardsType): void {
    let str: string = ''
    CardGroup.forEach((Card, i) => {
        str += Card.valueOf()+'\t'
        if ((i + 1) % 4 === 0) {
            str += '\n'
        }
    })
    console.log(str)
}